<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="dataForm" ref="dataForm" :errorType="['toast']" label-position="left" label-width="150"
			label-align="left">
			<u-form-item label="单别" v-if="judgeShow('ca001')">
				<u-input v-model="dataForm.ca001" placeholder="单别" :disabled="judgeWrite('ca001')"></u-input>
			</u-form-item>
			<u-form-item label="单号" v-if="judgeShow('ca002')">
				<u-input v-model="dataForm.ca002" placeholder="单号" :disabled="judgeWrite('ca002')"></u-input>
			</u-form-item>
			<u-form-item label="单据日期" v-if="judgeShow('ca018')">
				<u-input v-model="dataForm.ca018" placeholder="单据日期" :disabled="judgeWrite('ca018')"></u-input>
			</u-form-item>
			<u-form-item label="主件品号" v-if="judgeShow('ca003')">
				<u-input v-model="dataForm.ca003" placeholder="主件品号" :disabled="judgeWrite('ca003')"></u-input>
			</u-form-item>
			<u-form-item label="品名" v-if="judgeShow('mb002')">
				<u-input v-model="dataForm.mb002" placeholder="品名" :disabled="judgeWrite('mb002')"></u-input>
			</u-form-item>
			<u-form-item label="规格" v-if="judgeShow('mb003')">
				<u-input v-model="dataForm.mb003" placeholder="规格" :disabled="judgeWrite('mb003')"></u-input>
			</u-form-item>
			<u-form-item label="属性" v-if="judgeShow('mb025')">
				<u-input v-model="dataForm.mb025" placeholder="属性" :disabled="judgeWrite('mb025')"></u-input>
			</u-form-item>
			<u-form-item label="单位" v-if="judgeShow('ca004')">
				<u-input v-model="dataForm.ca004" placeholder="单位" :disabled="judgeWrite('ca004')"></u-input>
			</u-form-item>
			<u-form-item label="标准批量" v-if="judgeShow('ca006')">
				<u-input v-model="dataForm.ca006" placeholder="标准批量" :disabled="judgeWrite('ca006')"></u-input>
			</u-form-item>
			<u-form-item label="模具编号" v-if="judgeShow('udf01')">
				<u-input v-model="dataForm.udf01" placeholder="模具编号" :disabled="judgeWrite('udf01')"></u-input>
			</u-form-item>
			<u-form-item label="一次产品单重" v-if="judgeShow('udf02')">
				<u-input v-model="dataForm.udf02" placeholder="一次产品单重" :disabled="judgeWrite('udf02')"></u-input>
			</u-form-item>
			<u-form-item label="二次产品单重" v-if="judgeShow('udf03')">
				<u-input v-model="dataForm.udf03" placeholder="二次产品单重" :disabled="judgeWrite('udf03')"></u-input>
			</u-form-item>
			<u-form-item label="开机料" v-if="judgeShow('udf51')">
				<u-input v-model="dataForm.udf51" placeholder="开机料" :disabled="judgeWrite('udf51')"></u-input>
			</u-form-item>
			<u-form-item label="机台吨位" v-if="judgeShow('ca012')">
				<u-input v-model="dataForm.ca012" placeholder="机台吨位" :disabled="judgeWrite('ca012')"></u-input>
			</u-form-item>
			<u-form-item label="审核日期" v-if="judgeShow('ca022')">
				<u-input v-model="dataForm.ca022" placeholder="审核日期" :disabled="judgeWrite('ca022')"></u-input>
			</u-form-item>
			<u-form-item label="审核者" v-if="judgeShow('ca016')">
				<u-input v-model="dataForm.ca016" placeholder="审核者" :disabled="judgeWrite('ca016')"></u-input>
			</u-form-item>
			<u-form-item label="标准人数" v-if="judgeShow('udf55')">
				<u-input v-model="dataForm.udf55" placeholder="标准人数" :disabled="judgeWrite('udf55')"></u-input>
			</u-form-item>
			<u-form-item label="模穴数" v-if="judgeShow('udf52')">
				<u-input v-model="dataForm.udf52" placeholder="模穴数" :disabled="judgeWrite('udf52')"></u-input>
			</u-form-item>
			<u-form-item label="周期（秒）" v-if="judgeShow('udf53')">
				<u-input v-model="dataForm.udf53" placeholder="周期（秒）" :disabled="judgeWrite('udf53')"></u-input>
			</u-form-item>
			<u-form-item label="标准产能" v-if="judgeShow('udf54')">
				<u-input v-model="dataForm.udf54" placeholder="标准产能" :disabled="judgeWrite('udf54')"></u-input>
			</u-form-item>
			<u-form-item label="是否全自动" v-if="judgeShow('udf04')">
				<u-input v-model="dataForm.udf04" placeholder="是否全自动" :disabled="judgeWrite('udf04')"></u-input>
			</u-form-item>
			<u-form-item label="是否即冷即热" v-if="judgeShow('udf05')">
				<u-input v-model="dataForm.udf05" placeholder="是否即冷即热" :disabled="judgeWrite('udf05')"></u-input>
			</u-form-item>
			<u-form-item label="是否外接氮气" v-if="judgeShow('udf06')">
				<u-input v-model="dataForm.udf06" placeholder="是否外接氮气" :disabled="judgeWrite('udf06')"></u-input>
			</u-form-item>
			<u-form-item label="子件关系" v-if="judgeShow('ca013')">
				<u-tag :text="getTb019Computed(dataForm.ca013)" type="success" />
			</u-form-item>
			<u-form-item label="工单单别" v-if="judgeShow('ca007')">
				<u-input v-model="dataForm.ca007" placeholder="工单单别" :disabled="judgeWrite('ca007')"></u-input>
			</u-form-item>
			<u-form-item label="签核状态码" v-if="judgeShow('ca020')">
				<u-input v-model="dataForm.ca020" placeholder="签核状态码" :disabled="judgeWrite('ca020')"></u-input>
			</u-form-item>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<view class="jnpf-table-item" style="margin-bottom: 24rpx;" v-for="(item,i) in dataForm.bomcbList"
					:key="i">
					<u-form-item label="序号" style="background-color: aqua;">
						{{i+1}}
					</u-form-item>
					<u-form-item label="元件品号" v-if="judgeShow('bomcbList-cb005')">
						<u-input v-model="item.cb005" placeholder="元件品号" disabled></u-input>
					</u-form-item>
					<u-form-item label="品名" v-if="judgeShow('bomcbList-mb002')">
						<u-input v-model="item.mb002" placeholder="品名" disabled></u-input>
					</u-form-item>
					<u-form-item label="规格" v-if="judgeShow('bomcbList-mb003')">
						<u-input v-model="item.mb003" placeholder="规格" disabled></u-input>
					</u-form-item>
					<u-form-item label="单位" v-if="judgeShow('bomcbList-cb006')">
						<u-input v-model="item.cb006" placeholder="单位" disabled></u-input>
					</u-form-item>
					<u-form-item label="属性" v-if="judgeShow('bomcbList-mb025')">
						<u-input v-model="item.mb025" placeholder="属性" disabled></u-input>
					</u-form-item>
					<u-form-item label="组成用量" v-if="judgeShow('bomcbList-cb008')">
						<u-input v-model="item.cb008" placeholder="组成用量" disabled></u-input>
					</u-form-item>
					<u-form-item label="底数" v-if="judgeShow('bomcbList-cb009')">
						<u-input v-model="item.cb009" placeholder="底数" disabled></u-input>
					</u-form-item>
					<u-form-item label="损耗率" v-if="judgeShow('bomcbList-cb010')">
						<u-input v-model="item.cb010" placeholder="损耗率" disabled></u-input>
					</u-form-item>
					<u-form-item label="生效日期" v-if="judgeShow('bomcbList-cb013')">
						<u-input v-model="item.cb013" placeholder="生效日期" disabled></u-input>
					</u-form-item>
					<u-form-item label="失效日期" v-if="judgeShow('bomcbList-cb014')">
						<u-input v-model="item.cb014" placeholder="失效日期" disabled></u-input>
					</u-form-item>
					<u-form-item label="材料类型" v-if="judgeShow('bomcbList-cb019')">
						<u-input v-model="item.cb019" placeholder="材料类型" disabled></u-input>
					</u-form-item>
					<u-form-item label="交叉排程" v-if="judgeShow('bomcbList-cb032')">
						<u-input v-model="item.cb032" placeholder="交叉排程" disabled></u-input>
					</u-form-item>
					<u-form-item label="考虑上阶固定前置天数" v-if="judgeShow('bomcbList-cb023')">
						<u-input v-model="item.cb023" placeholder="考虑上阶固定前置天数" disabled></u-input>
					</u-form-item>
					<u-form-item label="工艺" v-if="judgeShow('bomcbList-cb011')">
						<u-input v-model="item.cb011" placeholder="工艺" disabled></u-input>
					</u-form-item>
					<u-form-item label="工艺名称" v-if="judgeShow('bomcbList-mw002')">
						<u-input v-model="item.mw002" placeholder="工艺名称" disabled></u-input>
					</u-form-item>
					<u-form-item label="投料间距" v-if="judgeShow('bomcbList-cb020')">
						<u-input v-model="item.cb020" placeholder="投料间距" disabled></u-input>
					</u-form-item>
					<u-form-item label="默认选择" v-if="judgeShow('bomcbList-cb015')">
						<u-input v-model="item.cb015" placeholder="默认选择" disabled></u-input>
					</u-form-item>
					<u-form-item label="标准成本计算" v-if="judgeShow('bomcbList-cb016')">
						<u-input v-model="item.cb016" placeholder="标准成本计算" disabled></u-input>
					</u-form-item>
					<u-form-item label="分量损耗" v-if="judgeShow('bomcbList-cb031')">
						<u-input v-model="item.cb031" placeholder="分量损耗" disabled></u-input>
					</u-form-item>
					<u-form-item label="固定损耗量" v-if="judgeShow('bomcbList-cb030')">
						<u-input v-model="item.cb030" placeholder="固定损耗量" disabled></u-input>
					</u-form-item>
					<u-form-item label="备注" v-if="judgeShow('bomcbList-cb018')">
						<u-input v-model="item.cb018" placeholder="备注" disabled></u-input>
					</u-form-item>
					<u-form-item label="组合替代" v-if="judgeShow('bomcbList-cb029')">
						<u-input v-model="item.cb029" placeholder="组合替代" disabled></u-input>
					</u-form-item>
					<u-form-item label="插件位置" v-if="judgeShow('bomcbList-cb017')">
						<u-input v-model="item.cb017" placeholder="插件位置" disabled></u-input>
					</u-form-item>
					<u-form-item label="水口品号" v-if="judgeShow('bomcbList-udf07')">
						<u-input v-model="item.udf07" placeholder="水口品号" disabled></u-input>
					</u-form-item>
					<u-form-item label="水品品名" v-if="judgeShow('bomcbList-udf01')">
						<u-input v-model="item.udf01" placeholder="水品品名" disabled></u-input>
					</u-form-item>
					<u-form-item label="水口规格" v-if="judgeShow('bomcbList-udf02')">
						<u-input v-model="item.udf02" placeholder="水口规格" disabled></u-input>
					</u-form-item>
					<u-form-item label="水口单重" v-if="judgeShow('bomcbList-udf03')">
						<u-input v-model="item.udf03" placeholder="水口单重" disabled></u-input>
					</u-form-item>
				</view>
			</view>
		</u-form>


	</view>
</template>

<script>
	import comMixin from '../mixin'
	import {
		getGoodsList,
		getCustomerList,
		Info,
		Create,
		Update,
	} from '@/api/apply/order'
	import {
		getBomca,
		BomcbListInit,

	} from '@/api/workFlow/flowBefore'
	import {
		getDictionaryDataSelector,
		getDataInterfaceDataInfo
	} from '@/api/common'
	export default {
		mixins: [comMixin],
		computed: {
			getTb019Computed() {
				return (id) => {
					const options = this.options.filter((item) => id.includes(item.id));
					return options.length > 0 ? options[0].fullName : '';
				};
			}
		},
		data() {
			return {
				show: false,
				dataForm: {},
				id: '',
				showForm: [],
				formOperatesList: [],
				options: [{
						fullName: "必选，唯一",
						id: "1"
					},
					{
						fullName: "必选，至少一个",
						id: "2"
					},
					{
						fullName: "可选，唯一",
						id: "3"
					},
					{
						fullName: "任意选",
						id: "4"
					},
				],
			}
		},
		methods: {
			init(data, id, flowFormContentJson) {
				this.setting = data
				this.formOperatesList = data.formOperates
				this.id = id
				this.getInfoFn(id)
			},
			getInfoFn(id) {
				getBomca({
					id
				}).then(res => {
					if (res.code == 200) {
						this.dataForm = res.data;
					}
				})
			},
			queryChildBachelor(tb004) {
				let query = {
					tb004
				};
				BomcbListInit(query).then((res) => {
					this.showForm = res.data;
					this.show = true;
				})
			},
			getDataInterfaceDataInfoMA003(id) {
				let data = {
					id,
					interfaceId: '362399109623061061',
					propsValue: 'MB001',
					relationField: 'MB001',
				}
				getDataInterfaceDataInfo('362399109623061061', data).then(res => {

				})
			},
			selfGetInfo() {
				Info(this.setting.id).then(res => {
					this.dataForm = res.data
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson)
					}
				})
			},
			selfSubmit() {
				this.dataForm.status = this.eventType === 'submit' ? 0 : 1
				if (this.eventType === 'save') return this.selfHandleRequest()
				uni.showModal({
					title: '提示',
					content: '您确定要提交当前流程吗？',
					success: res => {
						if (res.confirm) {
							this.selfHandleRequest()
						}
					}
				})
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete(this.dataForm.id)
				const formMethod = this.dataForm.id ? Update : Create
				formMethod(this.dataForm).then(res => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit('refresh')
								uni.navigateBack()
							}, 1500)
						}
					})
				})
			},
			initData() {
				getGoodsList().then(res => {
					this.goodsOptions = res.data.list
				})
				getCustomerList().then(res => {
					this.customerOptions = res.data.list
				})
			},
			selfInit() {
				this.addGoods()
				this.addPlan()
			},
			onChange(e) {
				const user = e[0]
				this.dataForm.salesmanName = user.fullName
			},
			addGoods() {
				const item = {
					goodsId: '',
					goodsCode: '',
					goodsName: '',
					specifications: '',
					unit: '',
					qty: '',
					price: '',
					amount: '',
					discount: null,
					cess: null,
					actualPrice: '',
					actualAmount: '',
					description: ''
				}
				this.dataForm.goodsList.push(item)
			},
			delGoods(index) {
				this.dataForm.goodsList.splice(index, 1)
			},
			addPlan() {
				const item = {
					receivableDate: '',
					receivableRate: '',
					receivableMoney: '',
					receivableMode: '',
					abstract: ''
				}
				this.dataForm.collectionPlanList.push(item)
			},
			delPlan(index) {
				this.dataForm.collectionPlanList.splice(index, 1)
			},
			onGoodsChange(e, i) {
				const goods = e[0]
				this.dataForm.goodsList[i] = {
					goodsId: goods.id,
					goodsCode: goods.code,
					goodsName: goods.text,
					specifications: goods.specifications,
					unit: goods.unit,
					qty: 1,
					price: goods.price,
					amount: goods.price,
					discount: 100,
					cess: 0,
					actualPrice: goods.price,
					actualAmount: goods.price,
					description: ''
				}
				this.$forceUpdate()
			},
			onCustomerChange(e) {
				const customer = e[0]
				this.dataForm.customerName = customer.text
			},
			count(row) {
				//金额 = 数量*单价
				row.amount = this.jnpf.toDecimal(parseFloat(row.price) * parseFloat(row.qty))
				//折扣价 = (单价*折扣)
				var discountPrice = row.price * (row.discount / 100);
				//实际单价 = 折扣价 * (1 + (税率 / 100))
				row.actualPrice = this.jnpf.toDecimal(discountPrice * (1 + (row.cess / 100)));
				//实际金额
				row.actualAmount = this.jnpf.toDecimal(parseFloat(row.actualPrice) * parseFloat(row
					.qty))
				this.$forceUpdate()
			}
		}
	}
</script>